<?php
 /*****************************************************************************
 * updateContact.php                                                          *
 * Last Modified: 2007-06-06                                                  *
 *                                                                            *
 * updateContact.php is the driver file used to update a contact record with  *
 * new data passed by POST from editContact.php.                              *
 *                                                                            *
 * BBG_Billing, a PHP application using MySQL for creating and maintaining a  *
 * contacts and invoices database.                                            *
 *                                                                            *
 * @copyright Copyright (C) 2007, Bugs Bee Gone Computer Services             *
 * @owner     Daniel Barnett (Bugs Bee Gone Computer Services)                *
 * @author    Daniel Barnett <dbarnett@bugsbeegone.com>                       *
 * @website   http://www.bugsbeegone.com                                      *
 * @license   http://www.gnu.org/licenses/gpl.html GNU General Public License *
 * @package   BBG_Billing                                                     *
 * @name      updateContact.php                                               *
 * @version   1.0.0                                                           *
 * @uses      Jpmaster77's Login Script (Written by: Jpmaster77, 2004-08-19)  *
 *             ->(http://www.evolt.org/PHP-Login-System-with-Admin-Features/) *
 *                                                                            *
 * This file is part of the "BBG_Billing" PHP application.                    *
 *                                                                            *
 * BBG_Billing is free software; you can redistribute it and/or modify        *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation; either version 2 of the License, or          *
 * (at your option) any later version.                                        *
 *                                                                            *
 * BBG_Billing is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with BBG_Billing; if not, write to the Free Software                 *
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
 *****************************************************************************/
 

    // Require session.php for user access control
    require "include/session.php";

    // Check to see if user is logged in, if not logged in redirect to main.php.
    if(!$session->logged_in){
        header("Location: main.php");
        exit();
    }

    // Require config.inc.php for configuration variables
    require_once "config.inc.php";

    // Check to see if key value was passed via POST, if it was...
    if ($_POST['key'] != "") {
        // Define data variables
        $key = $_POST['key'];
        $customerID = $_POST['customerID'];
        $company = $_POST['company'];
        $firstName = $_POST['firstName'];
        $lastName = $_POST['lastName'];
        $address1 = $_POST['address1'];
        $address2 = $_POST['address2'];
        $city = $_POST['city'];
        $state = $_POST['state'];
        $zipCode = $_POST['zipCode'];
        $phone1 = $_POST['phone1'];
        $phone2 = $_POST['phone2'];
        $fax = $_POST['fax'];
        $email = $_POST['email'];
        $webSite = $_POST['webSite'];
        $notes = $_POST['notes'];
		
        // Connect to MySQL
        mysql_connect($path, $username, $password);
        // Select database, if error die with error message
        @mysql_select_db($database) or die("Unable to select database.<br />" . mysql_error());

        // Define MySQL query to update contact record
        $query = "UPDATE tblContacts SET customerID='$customerID', company='$company', firstName='$firstName', lastName='$lastName', address1='$address1', address2='$address2', city='$city', state='$state', zipCode='$zipCode', phone1='$phone1', phone2='$phone2', fax='$fax', email='$email', webSite='$webSite', notes='$notes' WHERE `key`=$key";

        // Execute MySQL query, if error die with error message
        mysql_query($query) or die('<p style="color: red;">Update Failed.</p>' . mysql_error());

        // Close the connection
        mysql_close();

        // Output success message and redirect to contacts.php
        echo '<html>';
        echo '<head>';
            echo '<meta http-equiv="refresh" content="0;url=contacts.php" />';
        echo '</head>';

        echo '<body>';
            echo 'Update Successful';
        echo '</body>';
        echo '</html>';
		
    // If key value was not passed, die with error message.
    } else {
        die('<p style="color: red;">Error: Please provide the key of the contact to be updated.</p>');
    }
?>
